import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import com.sun.faces.util.MessageFactory;

/**
 * Class MailValidation, validator JSF qui valide une adresse mail d'un champ.
 *
 */
public class MailValidation implements Validator
{

	public void validate(FacesContext context, UIComponent component, Object value)
			throws ValidatorException
	{
		String enteredEmail = (String) value;
		Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
		Matcher m = p.matcher(enteredEmail);
		boolean matchFound = m.matches();

		if (!matchFound)
			throw new ValidatorException(MessageFactory.getMessage(context,
					"error_mailmalformed"));
	}

}
